package com.tm.utils;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ResponseUtil {
    public static void out(HttpServletResponse response, Object object){
        try (ServletOutputStream os = response.getOutputStream()){
            ObjectMapper objectMapper = new ObjectMapper();
            String jsonStr = objectMapper.writeValueAsString(object);
            response.setContentType("application/json;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            os.write(jsonStr.getBytes("utf-8"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}